﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.IO;
using Oracle.DataAccess.Client;
using Wicresoft.SelfService.DAL;
using Wicresoft.SelfService.DAO;
using Wicresoft.SelfService.BL.Interface;

namespace Wicresoft.SelfService.BL
{
    public class UserSync : IUserSync,IDisposable
    {
        private ITServiceDAL itService;
        public UserSync()
        {
            if (itService == null) itService = new ITServiceDAL();
        }

        public UserInfo getUserInfo(string accountID)
        {
            QueryParameters[] userInfoParam = new QueryParameters[] {
                new QueryParameters(){ OracleDbName="accountID", OracleDbType=OracleDbType.NVarchar2, OracleDbSize=20, OracleDbValue=accountID, QueryOperator=QueryOperatorType.equal, PredicateType=PredicateType.where}
            };
            UserInfo userInfo = itService.getUserInfo_By_QueryParams(userInfoParam, null, null, null).FirstOrDefault();
            return userInfo;
        }

        public UserInfo getUserInfo(string userName, string company)
        {
            QueryParameters[] userInfoParam = new QueryParameters[] {
                new QueryParameters(){ OracleDbName="userName", OracleDbType=OracleDbType.NVarchar2, OracleDbSize=20, OracleDbValue=userName, QueryOperator=QueryOperatorType.equal, PredicateType=PredicateType.where},            
                new QueryParameters(){ OracleDbName="Company", OracleDbType=OracleDbType.NVarchar2, OracleDbSize=20, OracleDbValue=company, QueryOperator=QueryOperatorType.equal, PredicateType=PredicateType.where}
           };
            UserInfo userInfo = itService.getUserInfo_By_QueryParams(userInfoParam, null, null, null).FirstOrDefault();
            return userInfo;
        }

        public void Dispose()
        {
            if (itService != null)
                itService.Dispose();
        }
    }
}
